/****************************************************************************/
/* Camera Character Device Driver Module (Exercise 03).                     */
/* Programmed by Ishai Jaffe (039713839) and Iddo Lazar (036829539)			*/
/****************************************************************************/

#include <linux/ioctl.h>


/*****************************************************************************/
/********************************* MACROS ************************************/
/*****************************************************************************/

#define MAJOR_NUM        387      /* Major number for the device */
#define DEVICE_NAME      "CAM-V4L2"    /* The name of the device */
#define FAMILY_NAME	     "FAMILY" /* Family used by the netlink com */
#define STD_CMD			  1       /* Standard cmd */
#define FAMILY_HEADER_LEN 0       /* Family header length */
#define NETLINK_PID_SOCK  1000    /* Netlink PID */

/*****************************************************************************/
/**************************** NETLINK ATTRIBUTES *****************************/
/*****************************************************************************/

#define MAX_ATTR_INDEX  	7 /* Maximum number of used attributes */
#define INIT_ATTR 			1 /* Defines a message from camera to driver in order to save struct net */
#define KILL_ATTR			2 /* Defines a message from camera to driver saying camera is dead (flv finito) */
#define STREAMON_ATTR 		3 /* Defines a message from driver to camera telling the camera to start capturing and send frames to driver */
#define STREAMOFF_ATTR		4 /* Defines a message from driver to camera telling the camera to stop capturing */
#define FRAME_ATTR			5 /* Defines a message from driver to camera requesting for frame and camera to driver sending frame */
#define RETURN_ATTR			6 /* Defines a message from camera to driver in order to let driver know the status of operation */
#define G_FMT_ATTR			7 /* Defines a message from driver to camera in order to get format */

#define	NL_PACKET_SIZE	4000
#define FRAME_BUFFER_SIZE	NL_PACKET_SIZE - 8

#ifdef _DEBUG
#	define DEBUG(x...) fprintf(stderr, "DEBUG: " x) /* Debugging function */
#else
#	define DEBUG(x...) ((void)(0))
#endif

#define ERROR(x...) fprintf(stderr, "ERROR: " x)

#define ERROR_ON(exp, msg...)  \
  do { if (exp) { ERROR(msg); goto err; } } while (0)

typedef struct
{
	int frame_finito;
	int length;
	char buffer[FRAME_BUFFER_SIZE];
} frame_packet;

#define MIN(a,b) ((a)>(b)?(b):(a))
